{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "from ilthermo.models import *\n",
    "ions = session.query(Ion)\n",
    "mols = session.query(Molecule)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Canonicalize SMILES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "for ion in ions.filter(Ion.ignored==False):\n",
    "    m = pybel.readstring('smi', ion.smiles)\n",
    "    ion.smiles = m.write('can').strip()\n",
    "session.commit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Check molcular formula"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "for mol in mols:\n",
    "    if not mol.cation.ignored and not mol.anion.ignored:\n",
    "        smiles = mol.cation.smiles + '.' + mol.anion.smiles\n",
    "        m = pybel.readstring('smi', smiles)\n",
    "        if mol.formula != m.formula:\n",
    "            print(mol, mol.formula, m.formula, mol.cation_id, mol.anion_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Check number of papers for each ion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "for ion in ions.filter(Ion.ignored==False):\n",
    "    ps = set()\n",
    "    for mol in ion.molecules:\n",
    "        for data in mol.datas:\n",
    "            ps.add(data.paper)\n",
    "    print(ion, len(ps))\n",
    "    ion.n_paper = len(ps)\n",
    "session.commit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Check duplicated ions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "pycharm": {},
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Ion -1: 22 bis(trifluoromethylsulfonyl)imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 87 bis((trifluoromethyl)sulfonyl)amide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 374 1-methyl-3-octylimidazolium> <Ion +1: 265 1-octyl-3-methylimidazolium>\n",
      "<Ion -1: 310 bis(trifluoromethylsulfonyl)amide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 93 1,1,1-trifluoro-N-[(trifluoromethyl)sulfonyl]methanesulfonamide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 740 methylsulfate> <Ion -1: 840 methyl sulfate>\n",
      "<Ion +1: 10 1-ethyl-3-methyl-1H-imidazolium> <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "<Ion -1: 97 bis(trifluoromethanesulfonyl)imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 98 ethylsulfate> <Ion -1: 841 ethyl sulfate>\n",
      "<Ion -1: 129 bis((trifluoromethyl)sulfonyl)imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 34 tricyanomethane> <Ion -1: 101 tricyanomethanide>\n",
      "<Ion +1: 445 tetradecyl(trihexyl)phosphonium> <Ion +1: 300 trihexyl(tetradecyl)phosphonium>\n",
      "<Ion +1: 552 trihexyltetradecylphosphonium> <Ion +1: 300 trihexyl(tetradecyl)phosphonium>\n",
      "<Ion +1: 35 1-butyl-3-methyl-1H-imidazolium> <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion +1: 405 1-propyl-3-methylimidazolium> <Ion +1: 277 1-methyl-3-propylimidazolium>\n",
      "<Ion +1: 456 3-hexyl-1-methyl-1H-imidazolium> <Ion +1: 264 1-hexyl-3-methylimidazolium>\n",
      "<Ion +1: 576 1-butyl-2,3-dimethyl-1H-imidazolium> <Ion +1: 267 1-butyl-2,3-dimethylimidazolium>\n",
      "<Ion -1: 94 bis(trifluromethylsulfonyl)imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 282 1-dodecyl-3-methylimidazolium> <Ion +1: 651 1-dodecyl-3-methyl-1H-imidazolium>\n",
      "<Ion +1: 614 3-ethyl-1-methyl-1H-imidazolium> <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "<Ion -1: 40 bis(perfluoroethylsulfonyl)imide> <Ion -1: 582 1,1,2,2,2-pentafluoro-N-[(pentafluoroethyl)sulfonyl]ethanesulfonamide>\n",
      "<Ion +1: 47 3-butyl-1-methyl-1H-imidazolium> <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion +1: 123 2-hydroxy-N,N,N-trimethylethanaminium> <Ion +1: 147 choline>\n",
      "<Ion -1: 577 trifluorotris(perfluoroethyl)phosphate(V)> <Ion -1: 39 tris(pentafluoroethyl)trifluorophosphate>\n",
      "<Ion +1: 601 3-ethyl-1-methylimidazolium> <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "<Ion -1: 26 tosylate> <Ion -1: 442 4-methylbenzenesulfonate>\n",
      "<Ion -1: 85 triflate> <Ion -1: 33 trifluoromethanesulfonate>\n",
      "<Ion -1: 444 p-toluenesulfonate> <Ion -1: 442 4-methylbenzenesulfonate>\n",
      "<Ion +1: 449 tetradecyltrihexylphosphonium> <Ion +1: 300 trihexyl(tetradecyl)phosphonium>\n",
      "<Ion +1: 493 3-hexyl-1-methylimidazolium> <Ion +1: 264 1-hexyl-3-methylimidazolium>\n",
      "<Ion -1: 229 bis[(trifluoromethyl)sulfonyl]amide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 271 hexafluorophosphate(V)> <Ion -1: 20 hexafluorophosphate>\n",
      "<Ion +1: 404 1-methyl-3-pentyl-imidazolium> <Ion +1: 273 1-methyl-3-pentylimidazolium>\n",
      "<Ion +1: 433 1-methyl-3-octyl-1H-imidazolium> <Ion +1: 265 1-octyl-3-methylimidazolium>\n",
      "<Ion +1: 638 1-benzyl-3-methyl-1H-imidazol-3-ium> <Ion +1: 268 1-benzyl-3-methylimidazolium>\n",
      "<Ion -1: 851 2-hydroxypropanoate> <Ion -1: 60 lactate>\n",
      "<Ion -1: 52 propanoate> <Ion -1: 106 propionate>\n",
      "<Ion -1: 102 1,1,2,2-tetrafluoroethane-1-sulfonate> <Ion -1: 70 1,1,2,2-tetrafluoroethanesulfonate>\n",
      "<Ion -1: 111 trifluorotris(perfluoroethyl)phosphate> <Ion -1: 39 tris(pentafluoroethyl)trifluorophosphate>\n",
      "<Ion +1: 462 1-pentyl-3-methylimidazolium> <Ion +1: 273 1-methyl-3-pentylimidazolium>\n",
      "<Ion -1: 496 ammonioacetate> <Ion -1: 63 glycinate>\n",
      "<Ion +1: 511 3-(2-hydroxyethyl)-1-methyl-1H-imidazol-3-ium> <Ion +1: 325 1-(2-hydroxyethyl)-3-methylimidazolium>\n",
      "<Ion -1: 512 dicyanoazanide> <Ion -1: 29 dicyanamide>\n",
      "<Ion +1: 518 1-benzyl-3-methyl-1H-imidazolium> <Ion +1: 268 1-benzyl-3-methylimidazolium>\n",
      "<Ion +1: 580 3-(2-hydroxyethyl)-1-methyl-1H-imidazolium> <Ion +1: 325 1-(2-hydroxyethyl)-3-methylimidazolium>\n",
      "<Ion +1: 643 1-methyl-3-nonylimidazolium> <Ion +1: 274 1-nonyl-3-methylimidazolium>\n",
      "<Ion -1: 83 bis((perfluoroethyl)sulfonyl)amide> <Ion -1: 582 1,1,2,2,2-pentafluoro-N-[(pentafluoroethyl)sulfonyl]ethanesulfonamide>\n",
      "<Ion +1: 116 2-hydroxy-N-methylethanaminium> <Ion +1: 117 N-methyl-2-hydroxyethylammonium>\n",
      "<Ion +1: 155 N-methyl-N,N-dioctyl-1-octanaminium> <Ion +1: 134 methyltrioctylammonium>\n",
      "<Ion +1: 183 n-butylammonium> <Ion +1: 182 butylammonium>\n",
      "<Ion +1: 303 1-(2-hydroxyethyl)-3-methyl-1H-imidazolium> <Ion +1: 325 1-(2-hydroxyethyl)-3-methylimidazolium>\n",
      "<Ion -1: 304 2,2,2-trifluoroacetate> <Ion -1: 21 trifluoroacetate>\n",
      "<Ion +1: 515 3-methyl-1-octylimidazolium> <Ion +1: 265 1-octyl-3-methylimidazolium>\n",
      "<Ion -1: 558 1,1,1-trifluoromethanesulfonate> <Ion -1: 33 trifluoromethanesulfonate>\n",
      "<Ion +1: 589 1-decyl-3-methyl-1H-imidazolium> <Ion +1: 281 1-decyl-3-methylimidazolium>\n",
      "<Ion +1: 848 N.N.N-tributyl-1-butanaminium> <Ion +1: 149 tetrabutylammonium>\n",
      "<Ion -1: 915 hydrogensulfate> <Ion -1: 878 hydrogen sulfate>\n",
      "<Ion -1: 3 bis(fluorosulfonyl)imide> <Ion -1: 6 bis(fluorosulfonyl)amide>\n",
      "<Ion +1: 55 3-butyl-1-methyl-1H-imidazol-3-ium> <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion +1: 61 3-butyl-1-methylimidazolium> <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion -1: 133 bis(trifluoromethylsulfonyl)imid> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 165 N,N-dibutyl-N-methyl-1-butanaminium> <Ion +1: 142 tributylmethylammonium>\n",
      "<Ion +1: 188 tetraethyammonium> <Ion +1: 190 tetraethylammonium>\n",
      "<Ion -1: 189 bis[(pentafluoroethyl)sulfonyl]imide> <Ion -1: 582 1,1,2,2,2-pentafluoro-N-[(pentafluoroethyl)sulfonyl]ethanesulfonamide>\n",
      "<Ion +1: 196 N,N,N-trihexyl-1-hexanaminium> <Ion +1: 145 tetrahexylammonium>\n",
      "<Ion +1: 203 hexyl(2-hydroxyethyl)dimethylammonium> <Ion +1: 131 N-(2-hydroxyethyl)-N,N-dimethylhexan-1-aminium>\n",
      "<Ion -1: 206 bis{(trifluomethyl)sulfonyl}imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 213 ethanolammonium> <Ion +1: 850 2-aminoethanol>\n",
      "<Ion -1: 214 butyrate> <Ion -1: 58 butanoate>\n",
      "<Ion +1: 278 3-(2-hydroxyethyl)-1-methylimidazolium> <Ion +1: 325 1-(2-hydroxyethyl)-3-methylimidazolium>\n",
      "<Ion +1: 330 1-allyl-3-methyl-1H-imidazolium> <Ion +1: 507 1-allyl-3-methylimidazolium>\n",
      "<Ion +1: 403 1-hexadecyl-3-methylimidazolium> <Ion +1: 635 3-hexadecyl-1-methyl-1H-imidazolium>\n",
      "<Ion +1: 411 1,3-dimethyl-1H-imidazolium> <Ion +1: 497 1,3-dimethylimidazolium>\n",
      "<Ion +1: 412 2-hydroxyethanaminium> <Ion +1: 850 2-aminoethanol>\n",
      "<Ion +1: 416 trihexyl(tetradecyl)-phosphonium> <Ion +1: 300 trihexyl(tetradecyl)phosphonium>\n",
      "<Ion -1: 509 cyanocyanamide> <Ion -1: 29 dicyanamide>\n",
      "<Ion +1: 529 1-methyl-3-hexylimidazolium> <Ion +1: 264 1-hexyl-3-methylimidazolium>\n",
      "<Ion +1: 536 1-(2-methoxyethyl)-3-methylimidazolium> <Ion +1: 283 1-(2-methoxyethyl)-3-methyl-imidazolium>\n",
      "<Ion +1: 539 1-octyl-3-methylpyridinium> <Ion +1: 402 N-octyl-3-methylpyridinium>\n",
      "<Ion +1: 551 3-(3-cyanopropyl)-1-methylimidazolium> <Ion +1: 508 1-(3-cyanopropyl)-3-methylimidazolium>\n",
      "<Ion +1: 569 2-hexylisoquinolinium> <Ion +1: 354 N-hexylisoquinolinium>\n",
      "<Ion +1: 597 3-ethyl-1-methyl-1H-imidazol-3-ium> <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "<Ion +1: 602 choline,> <Ion +1: 147 choline>\n",
      "<Ion +1: 607 1-ethyl-3-methyl-1H-imidazol-3-ium> <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "<Ion +1: 615 1-methyl-3-octyl-1H-imidazol-3-ium> <Ion +1: 265 1-octyl-3-methylimidazolium>\n",
      "<Ion +1: 619 3-methyl-1-propyl-1H-imidazolium> <Ion +1: 277 1-methyl-3-propylimidazolium>\n",
      "<Ion -1: 712 (bis(trifluoromethyl)sulfonyl)imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 722 bis[(trifluoromethyl)sulfonyl]azanide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 839 3-butyl-1-ethyl-1H-imidazolium> <Ion +1: 285 1-butyl-3-ethylimidazolium>\n",
      "<Ion -1: 843 dimethyl phosphate> <Ion -1: 36 dimethylphosphate>\n",
      "<Ion +1: 852 3-butyl-1-methyl-1H-Imidazolium> <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion +1: 892 1-metyl-3-propylimidazolium> <Ion +1: 277 1-methyl-3-propylimidazolium>\n",
      "<Ion -1: 894 diethyl phosphate> <Ion -1: 751 diethylphosphate>\n",
      "<Ion +1: 896 1,3-diethyl-1H-imidazol-3-ium> <Ion +1: 312 1,3-diethylimidazolium>\n",
      "<Ion -1: 911 lauric acid> <Ion -1: 822 dodecanoate>\n",
      "<Ion -1: 936 decanoic acid> <Ion -1: 788 decanoate>\n",
      "<Ion +1: 82 1-methyl-1-propylpyrrolidin-1-ium> <Ion +1: 5 1-methyl-1-propylpyrrolidinium>\n",
      "<Ion +1: 86 N,N-diethyl-N-methylpropan-1-aminium> <Ion +1: 7 N,N-diethyl-N-methyl-N-propylammonium>\n",
      "<Ion +1: 112 N-butylpyridinium> <Ion +1: 12 1-butylpyridinium>\n",
      "<Ion -1: 114 bis(nonafluorobutylsulfonyl)imide> <Ion -1: 43 bis(perfluorobutylsulfonyl)amide>\n",
      "<Ion -1: 118 isobutyrate> <Ion -1: 71 2-methylpropanoate>\n",
      "<Ion +1: 154 N-methyl-N,N,N-trioctylammonium> <Ion +1: 134 methyltrioctylammonium>\n",
      "<Ion +1: 162 N-ethyl-2-hydroxy-N,N-dimethylethanaminium> <Ion +1: 205 ethyl(2-hydroxyethyl)dimethylammonium>\n",
      "<Ion -1: 163 1-butanesulfonate> <Ion -1: 107 butylsulfonate>\n",
      "<Ion +1: 168 N,N-dibutyl-N-methylbutanaminium> <Ion +1: 142 tributylmethylammonium>\n",
      "<Ion -1: 169 2-aminoethanesulfonate> <Ion -1: 65 taurate>\n",
      "<Ion +1: 170 N,N,N-trimethyl-1-butanaminium> <Ion +1: 126 butyltrimethylammonium>\n",
      "<Ion +1: 178 N-(2-hydroxyethyl)-N,N-dimethyl-1-propanaminium> <Ion +1: 125 N-(2-hydroxyethyl)-N,N-dimethylpropanaminium>\n",
      "<Ion +1: 191 N,N,N-trioctyl-N-methylammonium> <Ion +1: 134 methyltrioctylammonium>\n",
      "<Ion +1: 192 N,N,N-triheptylheptan-1-aminium> <Ion +1: 887 N,N,N-triheptyl-1-heptanaminium>\n",
      "<Ion +1: 197 N-heptyl-N,N,N-trihexylammonium> <Ion +1: 193 N,N,N-trihexylheptan-1-aminium>\n",
      "<Ion +1: 198 N-ethyl-2-hydroxyethyl-N,N-dimethylammonium> <Ion +1: 205 ethyl(2-hydroxyethyl)dimethylammonium>\n",
      "<Ion +1: 207 hexadecyltrimethylammonium> <Ion +1: 226 N,N,N-trimethyl-1-hexadecanaminium>\n",
      "<Ion +1: 223 N,N,N-trimethyl-1-octadecanaminium> <Ion +1: 219 octadecyltrimethylammonium>\n",
      "<Ion +1: 224 N,N,N-trimethyl-1-decanaminium> <Ion +1: 159 N,N,N-Trimethyl-1-decanaminium>\n",
      "<Ion +1: 225 N,N,N-trimethyl-1-dodecanaminium> <Ion +1: 221 dodecyltrimethylammonium>\n",
      "<Ion +1: 227 N,N,N-trimethyl-1-tetradecanaminium> <Ion +1: 222 tetradecyltrimethylammonium>\n",
      "<Ion +1: 231 N,N,N-triethyloctan-1-aminium> <Ion +1: 135 triethyloctylammonium>\n",
      "<Ion -1: 232 hexafluorostibate> <Ion -1: 37 hexafluoroantimonate>\n",
      "<Ion +1: 233 N,N,N-triethyl-N-octylammonium> <Ion +1: 135 triethyloctylammonium>\n",
      "<Ion +1: 234 N,N,N-triethyl-N-hexylammonium> <Ion +1: 128 triethylhexylammonium>\n",
      "<Ion +1: 236 N-decyl-N,N-dimethyldecan-1-aminium> <Ion +1: 204 Didecyldimethylammonium>\n",
      "<Ion +1: 238 butyltriisoamylammonium> <Ion +1: 194 butyltris(3-methylbutyl)ammonium>\n",
      "<Ion -1: 240 trifluoro(perfluoroethyl)phosphate> <Ion -1: 39 tris(pentafluoroethyl)trifluorophosphate>\n",
      "<Ion +1: 241 N-decyldecan-1-aminium> <Ion +1: 120 didecylammonium>\n",
      "<Ion +1: 245 N-octyloctan-1-aminium> <Ion +1: 121 N-octyl-1-octaminium>\n",
      "<Ion +1: 248 tributylhexylammonium> <Ion +1: 237 N,N,N-tributyl-N-hexylammonium>\n",
      "<Ion +1: 252 N,N,N-tributyloctan-1-aminium> <Ion +1: 250 tributyloctylammonium>\n",
      "<Ion +1: 255 Butyronitriletrimethylammonium> <Ion +1: 254 butyronitriletrimethylammonium>\n",
      "<Ion +1: 257 2-methoxy-N-ethyl-N,N-dimethylethan-1-aminium> <Ion +1: 181 ethyldimethyl-(2-methoxyethyl)ammonium>\n",
      "<Ion +1: 259 N-ethyl-2-methoxy-N,N-dimethylethan-1-aminium> <Ion +1: 181 ethyldimethyl-(2-methoxyethyl)ammonium>\n",
      "<Ion +1: 299 1-methyl-3-octadecylimidazolium> <Ion +1: 369 3-methyl-1-octadecyl-1H-imidazolium>\n",
      "<Ion +1: 301 1-butyronitrile-3-methylimidazolium> <Ion +1: 508 1-(3-cyanopropyl)-3-methylimidazolium>\n",
      "<Ion +1: 308 N,N,N',N'-tetramethylguanidine> <Ion +1: 560 1,1,3,3-tetramethylguanidinium>\n",
      "<Ion +1: 326 3-(cyanomethyl)-1-methyl-1H-imidazol-3-ium> <Ion +1: 627 1-(cyanomethyl)-3-methylimidazolium>\n",
      "<Ion +1: 352 1-octyl-3-methylpydridinium> <Ion +1: 402 N-octyl-3-methylpyridinium>\n",
      "<Ion +1: 406 1-(3-aminopropyl)-3-methyl-1H-imidazolium> <Ion +1: 275 3-(3-aminopropyl)-1-methyl-1H-imidazolium>\n",
      "<Ion +1: 407 3-(2-aminoethyl)-1-methyl-1H-imidazolium> <Ion +1: 276 1-(2-aminoethyl)-3-methyl-1H-imidazolium>\n",
      "<Ion +1: 420 3-butyl-1,2,4,5-tetramethyl-1H-imidazol-3-ium> <Ion +1: 367 1-butyl-2,3,4,5-tetramethylimidazolium>\n",
      "<Ion +1: 441 1-methyl-4-amino-1,2,4-triazolium> <Ion +1: 593 4-amino-1-methyl-4H-1,2,4-triazol-1-ium>\n",
      "<Ion +1: 448 N-butyl-4-methylpyridinium> <Ion +1: 313 1-butyl-4-methylpyridinium>\n",
      "<Ion +1: 454 1-methyl-1-pentylpyrrolidinium> <Ion +1: 653 1-pentyl-1-methylpyrrolidinium>\n",
      "<Ion +1: 465 1-isopropyl-3-methylimidazolium> <Ion +1: 297 1-methyl-3-(1-methylethyl)imidazolium>\n",
      "<Ion +1: 471 1,3-dibutylimidazolium> <Ion +1: 314 1,3-dibutyl-1H-imidazolium>\n",
      "<Ion +1: 484 1-(2-hydroxyethyl)pyridinium> <Ion +1: 334 1-(2-hydroxyethyl)-pyridinium>\n",
      "<Ion -1: 499 glycine> <Ion -1: 63 glycinate>\n",
      "<Ion -1: 501 glycollate> <Ion -1: 59 glycolate>\n",
      "<Ion -1: 505 di(dicyanamide)> <Ion -1: 29 dicyanamide>\n",
      "<Ion -1: 506 dicyanoamide> <Ion -1: 29 dicyanamide>\n",
      "<Ion +1: 517 3-(3-cyanopropyl)-1,2-dimethylimidazolium> <Ion +1: 302 1-butyronitrile-2,3-dimethylimidazolium>\n",
      "<Ion +1: 535 N-octylpyridinium> <Ion +1: 376 1-octylpyridinium>\n",
      "<Ion +1: 545 1-propyl-3-methylpyridinium> <Ion +1: 311 3-methyl-1-propylpyridinium>\n",
      "<Ion +1: 565 methyltributylphosphonium> <Ion +1: 864 tributylmethylphosphonium>\n",
      "<Ion +1: 566 3-decyl-1-methylimidazolium> <Ion +1: 281 1-decyl-3-methylimidazolium>\n",
      "<Ion +1: 567 N-butyl-4-cyanopyridinium> <Ion +1: 345 1-butyl-4-cyanopyridinium>\n",
      "<Ion +1: 571 3-butyl-1-(2-cyanoethyl)-imidazolium> <Ion +1: 523 3-butyl-1-(2-cyanoethyl)-1H-imidazol-3-ium>\n",
      "<Ion +1: 573 3-decyl-1-methyl-1H-imidazolium> <Ion +1: 281 1-decyl-3-methylimidazolium>\n",
      "<Ion +1: 583 2,3-dimethyl-1-propyl-1H-imidazol-3-ium> <Ion +1: 298 1,2-dimethyl-3-propylimidazolium>\n",
      "<Ion +1: 584 1-methyl-3-propyl-1H-imidazolium> <Ion +1: 277 1-methyl-3-propylimidazolium>\n",
      "<Ion -1: 585 1,1,2,2,2-pentafluoro-N-[(1,1,2,2,2-pentafluoroethyl)sulfonyl]ethanesulfonimidate> <Ion -1: 582 1,1,2,2,2-pentafluoro-N-[(pentafluoroethyl)sulfonyl]ethanesulfonamide>\n",
      "<Ion -1: 586 1,1,2,2,2-pentafluoro-N-[(1,1,2,2,2-pentafluoroethyl)sulfonyl]ethanesulfonamide> <Ion -1: 582 1,1,2,2,2-pentafluoro-N-[(pentafluoroethyl)sulfonyl]ethanesulfonamide>\n",
      "<Ion +1: 592 1-(2-azidoethyl)-4-methyl-4H-1,2,4-triazol-1-ium> <Ion +1: 389 4-(2-azidoethyl)-1-methyl-4H-1,2,4-triazol-1-ium>\n",
      "<Ion +1: 596 cholinium> <Ion +1: 147 choline>\n",
      "<Ion -1: 600 tris[(trifluoromethyl)sulfonyl]methanide> <Ion -1: 49 tris[(trifluoromethyl)sulfonyl]methide>\n",
      "<Ion -1: 611 pivalate> <Ion -1: 69 2,2-dimethylpropanoate>\n",
      "<Ion +1: 612 1-allyl-3-methyl-1H-imidazol-3-ium> <Ion +1: 507 1-allyl-3-methylimidazolium>\n",
      "<Ion +1: 616 1-methyl-3-propyl-1H-imidazol-3-ium> <Ion +1: 277 1-methyl-3-propylimidazolium>\n",
      "<Ion +1: 617 thallium> <Ion +1: 908 thallium(1+)>\n",
      "<Ion -1: 618 methanoate> <Ion -1: 57 formate>\n",
      "<Ion +1: 623 3-(2-cyanoethyl)-1-decylimidazolium> <Ion +1: 455 3-(2-cyanoethyl)-1-decyl-1H-imidazolium>\n",
      "<Ion +1: 630 1-hexadecylpyridinium> <Ion +1: 549 cetylpyridinium>\n",
      "<Ion +1: 650 3-methyl-1-undecyl-1H-imidazol-3-ium> <Ion +1: 409 1-undecyl-3-methylimidazolium>\n",
      "<Ion +1: 654 Tributylmethylphosphonium> <Ion +1: 864 tributylmethylphosphonium>\n",
      "<Ion +1: 660 1,2-diethylpyridin-1-ium> <Ion +1: 746 1,2-diethylpyridinium>\n",
      "<Ion -1: 679 bis(trifluoromethanesulfonyl)amide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion -1: 714 bis(trifluoromethanesulfonyl)-imide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 747 N-butyl-3-methylpyridinium> <Ion +1: 280 1-butyl-3-methylpyridinium>\n",
      "<Ion -1: 748 1,1,2,2,3,3,4,4,4-nonafluorobutane-1-sulfonate> <Ion -1: 100 perfluorobutanesulfonate>\n",
      "<Ion -1: 749 1,1,2,2,3,3,4,4,4-nonafluoro-1-butanesulfonate> <Ion -1: 100 perfluorobutanesulfonate>\n",
      "<Ion +1: 750 2-hydroxy-N,N,N-trimethylethanaminiume> <Ion +1: 147 choline>\n",
      "<Ion -1: 752 taurinate> <Ion -1: 65 taurate>\n",
      "<Ion +1: 766 2-hydroxy-N,N,N-trimethyl-ethanaminium> <Ion +1: 147 choline>\n",
      "<Ion +1: 767 2-hydroxy-N,N,N-trimethylethan-1-aminium> <Ion +1: 147 choline>\n",
      "<Ion -1: 771 1,4-bis((2-ethylhexyl)oxy)-1,4-dioxobutane-2-sulfonate> <Ion -1: 177 docusate>\n",
      "<Ion +1: 795 1-hexyl-1-methylpiperidin-1-ium> <Ion +1: 331 1-hexyl-1-methylpiperidinium>\n",
      "<Ion +1: 797 N-ethyl-N-methylpyrrolidinium> <Ion +1: 366 1-ethyl-1-methylpyrrolidinium>\n",
      "<Ion -1: 798 ethylphosphonate> <Ion -1: 881 ethyl phosphonate>\n",
      "<Ion +1: 799 N-hexyl-N-methylpyrrolidinium> <Ion +1: 574 1-hexyl-1-methylpyrrolidinium>\n",
      "<Ion +1: 800 N-methyl-N-octylpyrrolidinium> <Ion +1: 668 1-methyl-1-octylpyrrolidinium>\n",
      "<Ion +1: 804 3-(2-cyanoethyl)-1-octylimidazolium> <Ion +1: 451 3-(2-cyanoethyl)-1-octyl-1H-imidazolium>\n",
      "<Ion -1: 806 dodecylsulfate> <Ion -1: 902 dodecyl sulfate>\n",
      "<Ion +1: 827 4-ethyl-4-methylmorpholin-4-ium> <Ion +1: 865 4-ethyl-4-methylmorpholinium>\n",
      "<Ion -1: 830 2-dodecylbenzenesulfonate> <Ion -1: 794 dodecyl-benzenesulfonate>\n",
      "<Ion +1: 831 N-hexyl-1-hexanamine> <Ion +1: 253 dihexylammonium>\n",
      "<Ion +1: 844 1-(2-hydroxyethyl)-1-methylpyrrolidinium> <Ion +1: 669 1-(2-hydroxyethyl)-1-methylpyrrolidin-1-ium>\n",
      "<Ion -1: 854 bis 1,1,1-trifluoro-N-((trifluoromethyl)sulfonyl)methanesulfonamide> <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "<Ion +1: 866 N-ethyl-N-(2-hydroxyethyl)-N,N-dimethylammonium> <Ion +1: 205 ethyl(2-hydroxyethyl)dimethylammonium>\n",
      "<Ion +1: 890 3-methyl-1-pentylimidazolium> <Ion +1: 273 1-methyl-3-pentylimidazolium>\n",
      "<Ion +1: 895 2,3-dimethyl-1-propylimidazolium> <Ion +1: 298 1,2-dimethyl-3-propylimidazolium>\n",
      "<Ion +1: 897 1-butyl-1-methylpiperidin-1-ium> <Ion +1: 327 1-butyl-1-methylpiperidinium>\n",
      "<Ion +1: 899 1-ethyl-1-methylpiperidin-1-ium> <Ion +1: 364 1-ethyl-1-methylpiperidinium>\n",
      "<Ion +1: 900 1-butyl-1-methylpyrrolidin-1-ium> <Ion +1: 14 1-butyl-1-methylpyrrolidinium>\n",
      "<Ion +1: 903 1-butyl-3-(2-cyanoethyl)-1H-imidazol-3-ium> <Ion +1: 523 3-butyl-1-(2-cyanoethyl)-1H-imidazol-3-ium>\n",
      "<Ion -1: 909 stearic acid> <Ion -1: 824 stearate>\n",
      "<Ion -1: 939 octadecanoic acid> <Ion -1: 824 stearate>\n",
      "<Ion -1: 940 dodecanoic acid> <Ion -1: 822 dodecanoate>\n",
      "<Ion +1: 941 cyclohexylamine> <Ion +1: 937 cyclohexanamine>\n",
      "<Ion -1: 943 hexadecanoic acid> <Ion -1: 910 palmitic acid>\n",
      "<Ion +1: 846 N,N,N-trihexyl-1-heptanaminium> <Ion +1: 193 N,N,N-trihexylheptan-1-aminium>\n",
      "<Ion +1: 856 N-ethyl-N,N-dimethyl-2-methoxyethylammonium> <Ion +1: 181 ethyldimethyl-(2-methoxyethyl)ammonium>\n"
     ]
    }
   ],
   "source": [
    "smiles_ion = dict()\n",
    "for ion in ions.filter(Ion.ignored==False).order_by(Ion.n_paper.desc()):\n",
    "    if ion.smiles not in smiles_ion.keys():\n",
    "        smiles_ion[ion.smiles] = ion\n",
    "    else:\n",
    "        print(ion, smiles_ion[ion.smiles])\n",
    "        ion.duplicate = smiles_ion[ion.smiles].id\n",
    "session.commit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Check number of papers for unique ion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "for ion in ions.filter(Ion.ignored==False).order_by(Ion.n_paper.desc()):\n",
    "    if ion.duplicate is not None:\n",
    "        ion.times = 0\n",
    "    else:\n",
    "        ion.times = ion.n_paper\n",
    "        for eqi in ions.filter(Ion.duplicate==ion.id):\n",
    "            ion.times += eqi.n_paper\n",
    "session.commit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Show number of heavy atoms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "is_executing": false
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 <Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "9 <Ion +1: 5 1-methyl-1-propylpyrrolidinium>\n",
      "9 <Ion -1: 6 bis(fluorosulfonyl)amide>\n",
      "12 <Ion +1: 8 1-hexylpyridinium>\n",
      "8 <Ion +1: 11 1-ethylpyridinium>\n",
      "10 <Ion +1: 12 1-butylpyridinium>\n",
      "10 <Ion +1: 14 1-butyl-1-methylpyrrolidinium>\n",
      "7 <Ion -1: 20 hexafluorophosphate>\n",
      "7 <Ion -1: 21 trifluoroacetate>\n",
      "4 <Ion -1: 23 nitrate>\n",
      "5 <Ion -1: 24 tetrafluoroborate>\n",
      "4 <Ion -1: 28 acetate>\n",
      "5 <Ion -1: 29 dicyanamide>\n",
      "1 <Ion -1: 30 chloride>\n",
      "8 <Ion -1: 33 trifluoromethanesulfonate>\n",
      "7 <Ion -1: 36 dimethylphosphate>\n",
      "3 <Ion -1: 38 thiocyanate>\n",
      "9 <Ion -1: 41 tetracyanoborate>\n",
      "5 <Ion -1: 42 perchlorate>\n",
      "5 <Ion -1: 54 methanesulfonate>\n",
      "3 <Ion -1: 57 formate>\n",
      "15 <Ion -1: 81 bis[(trifluoromethyl)sulfonyl]imide>\n",
      "7 <Ion -1: 101 tricyanomethanide>\n",
      "8 <Ion +1: 105 1-ethyl-3-methylimidazolium>\n",
      "5 <Ion -1: 106 propionate>\n",
      "8 <Ion +1: 126 butyltrimethylammonium>\n",
      "6 <Ion +1: 172 diethylmethylammonium>\n",
      "12 <Ion +1: 264 1-hexyl-3-methylimidazolium>\n",
      "11 <Ion +1: 327 1-butyl-1-methylpiperidinium>\n",
      "8 <Ion +1: 366 1-ethyl-1-methylpyrrolidinium>\n",
      "9 <Ion -1: 751 diethylphosphate>\n",
      "15 <Ion +1: 812 tributylethylphosphonium>\n",
      "6 <Ion -1: 840 methyl sulfate>\n",
      "7 <Ion -1: 841 ethyl sulfate>\n",
      "14 <Ion +1: 864 tributylmethylphosphonium>\n"
     ]
    }
   ],
   "source": [
    "for ion in ions.filter(Ion.selected==True):\n",
    "    print(ion.n_heavy, ion)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Select molecules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "pycharm": {},
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cIm aSI <Molecule: 1 1-butyl-3-methylimidazolium bis(fluorosulfonyl)imide>\n",
      "cPyrr aSI <Molecule: 3 1-methyl-1-propylpyrrolidinium bis(fluorosulfonyl)amide>\n",
      "cPy aSI <Molecule: 5 1-hexylpyridinium bis(fluorosulfonyl)amide>\n",
      "cIm aSI <Molecule: 7 1-ethyl-3-methyl-1H-imidazolium bis(fluorosulfonyl)amide>\n",
      "cPy aSI <Molecule: 8 1-ethylpyridinium bis(fluorosulfonyl)amide>\n",
      "cPy aSI <Molecule: 9 1-butylpyridinium bis(fluorosulfonyl)amide>\n",
      "cPyrr aSI <Molecule: 11 1-butyl-1-methylpyrrolidinium bis(fluorosulfonyl)amide>\n",
      "cIm aXP6 <Molecule: 17 1-butyl-3-methylimidazolium hexafluorophosphate>\n",
      "cIm aCO2 <Molecule: 18 1-butyl-3-methylimidazolium trifluoroacetate>\n",
      "cIm aSI <Molecule: 19 1-butyl-3-methylimidazolium bis(trifluoromethylsulfonyl)imide>\n",
      "cIm aNO3 <Molecule: 20 1-butyl-3-methylimidazolium nitrate>\n",
      "cIm aXB4 <Molecule: 21 1-butyl-3-methylimidazolium tetrafluoroborate>\n",
      "cIm aCO2 <Molecule: 25 1-butyl-3-methylimidazolium acetate>\n",
      "cIm aNC[N] <Molecule: 26 1-butyl-3-methylimidazolium dicyanamide>\n",
      "cIm a0Cl <Molecule: 27 1-butyl-3-methylimidazolium chloride>\n",
      "cIm aSO3 <Molecule: 30 1-butyl-3-methylimidazolium trifluoromethanesulfonate>\n",
      "cIm aNC[C] <Molecule: 31 1-butyl-3-methylimidazolium tricyanomethane>\n",
      "cIm aPO2 <Molecule: 32 1-butyl-3-methyl-1H-imidazolium dimethylphosphate>\n",
      "cIm aNC[S] <Molecule: 34 1-butyl-3-methylimidazolium thiocyanate>\n",
      "cIm aNC[B] <Molecule: 37 1-butyl-3-methyl-1H-imidazolium tetracyanoborate>\n",
      "cIm aClO4 <Molecule: 38 1-butyl-3-methylimidazolium perchlorate>\n",
      "cIm aCO2 <Molecule: 47 3-butyl-1-methyl-1H-imidazolium propanoate>\n",
      "cIm aSO3 <Molecule: 49 1-butyl-3-methylimidazolium methanesulfonate>\n",
      "cIm aCO2 <Molecule: 51 3-butyl-1-methyl-1H-imidazolium formate>\n",
      "cPyrr aSI <Molecule: 76 1-methyl-1-propylpyrrolidinium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cPyrr aSO3 <Molecule: 80 1-methyl-1-propylpyrrolidinium triflate>\n",
      "cPyrr aXP6 <Molecule: 81 1-methyl-1-propylpyrrolidinium hexafluorophosphate>\n",
      "cPyrr aNC[S] <Molecule: 82 1-methyl-1-propylpyrrolidinium thiocyanate>\n",
      "cPy aXB4 <Molecule: 89 1-hexylpyridinium tetrafluoroborate>\n",
      "cPy aSI <Molecule: 91 1-hexylpyridinium bis(trifluromethylsulfonyl)imide>\n",
      "cPy a0Cl <Molecule: 95 1-hexylpyridinium chloride>\n",
      "cPy aNC[N] <Molecule: 96 1-hexylpyridinium dicyanamide>\n",
      "cIm aNC[C] <Molecule: 101 1-ethyl-3-methyl-1H-imidazolium tricyanomethanide>\n",
      "cIm aCO2 <Molecule: 105 1-ethyl-3-methylimidazolium propionate>\n",
      "cPy aXP6 <Molecule: 108 1-ethylpyridinium hexafluorophosphate>\n",
      "cPy aSI <Molecule: 111 1-ethylpyridinium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cPy aSO3 <Molecule: 112 1-ethylpyridinium triflate>\n",
      "cPy aNC[N] <Molecule: 114 1-ethylpyridinium dicyanamide>\n",
      "cPy aSO3 <Molecule: 115 1-ethylpyridinium methanesulfonate>\n",
      "cPy aXB4 <Molecule: 116 1-ethylpyridinium tetrafluoroborate>\n",
      "cPy aCO2 <Molecule: 117 1-ethylpyridinium trifluoroacetate>\n",
      "cPy aXB4 <Molecule: 118 1-butylpyridinium tetrafluoroborate>\n",
      "cPy aSO3 <Molecule: 119 1-butylpyridinium trifluoromethanesulfonate>\n",
      "cPy aSI <Molecule: 120 1-butylpyridinium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cPy aNO3 <Molecule: 121 1-butylpyridinium nitrate>\n",
      "cPy aNC[N] <Molecule: 124 1-butylpyridinium dicyanamide>\n",
      "cPyrr aSI <Molecule: 126 1-butyl-1-methylpyrrolidinium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cPyrr aNC[B] <Molecule: 127 1-butyl-1-methylpyrrolidinium tetracyanoborate>\n",
      "cPyrr aSO3 <Molecule: 129 1-butyl-1-methylpyrrolidinium trifluoromethanesulfonate>\n",
      "cPyrr aNC[N] <Molecule: 130 1-butyl-1-methylpyrrolidinium dicyanamide>\n",
      "cPyrr aNC[C] <Molecule: 131 1-butyl-1-methylpyrrolidinium tricyanomethanide>\n",
      "cPyrr aCO2 <Molecule: 132 1-butyl-1-methylpyrrolidinium trifluoroacetate>\n",
      "cPyrr aCO2 <Molecule: 133 1-butyl-1-methylpyrrolidinium acetate>\n",
      "cPyrr aNC[S] <Molecule: 134 1-butyl-1-methylpyrrolidinium thiocyanate>\n",
      "cPyrr aXB4 <Molecule: 139 1-butyl-1-methylpyrrolidinium tetrafluoroborate>\n",
      "cN4 aSI <Molecule: 153 butyltrimethylammonium bis(trifluoromethylsulfonyl)imide>\n",
      "cN4 aSO3 <Molecule: 195 diethylmethylammonium trifluoromethanesulfonate>\n",
      "cIm aXP6 <Molecule: 345 1-hexyl-3-methylimidazolium hexafluorophosphate>\n",
      "cIm aXP6 <Molecule: 347 1-ethyl-3-methylimidazolium hexafluorophosphate>\n",
      "cIm aCO2 <Molecule: 384 1-ethyl-3-methylimidazolium trifluoroacetate>\n",
      "cIm aCO2 <Molecule: 386 1-hexyl-3-methylimidazolium trifluoroacetate>\n",
      "cIm aSI <Molecule: 391 1-ethyl-3-methylimidazolium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cIm aSI <Molecule: 392 1-hexyl-3-methylimidazolium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cN4pi aSI <Molecule: 418 1-butyl-1-methylpiperidinium bis(trifluoromethanesulfonyl)imide>\n",
      "cPyrr aSI <Molecule: 459 1-ethyl-1-methylpyrrolidinium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cIm aNO3 <Molecule: 469 1-hexyl-3-methylimidazolium nitrate>\n",
      "cIm aNO3 <Molecule: 471 1-ethyl-3-methylimidazolium nitrate>\n",
      "cIm aXB4 <Molecule: 500 1-ethyl-3-methylimidazolium tetrafluoroborate>\n",
      "cIm aXB4 <Molecule: 501 1-hexyl-3-methylimidazolium tetrafluoroborate>\n",
      "cPyrr aXB4 <Molecule: 557 1-ethyl-1-methylpyrrolidinium tetrafluoroborate>\n",
      "cIm aCO2 <Molecule: 645 1-ethyl-3-methylimidazolium acetate>\n",
      "cIm aCO2 <Molecule: 646 3-hexyl-1-methylimidazolium acetate>\n",
      "cIm aNC[N] <Molecule: 666 1-ethyl-3-methylimidazolium dicyanamide>\n",
      "cIm aNC[N] <Molecule: 667 1-hexyl-3-methylimidazolium dicyanamide>\n",
      "cN4pi aNC[N] <Molecule: 675 1-butyl-1-methylpiperidinium dicyanamide>\n",
      "cIm a0Cl <Molecule: 692 1-ethyl-3-methylimidazolium chloride>\n",
      "cIm a0Cl <Molecule: 693 1-hexyl-3-methylimidazolium chloride>\n",
      "cIm aSO3 <Molecule: 749 1-ethyl-3-methylimidazolium trifluoromethanesulfonate>\n",
      "cIm aSO3 <Molecule: 750 1-hexyl-3-methylimidazolium trifluoromethanesulfonate>\n",
      "cN4pi aSO3 <Molecule: 761 1-butyl-1-methylpiperidinium trifluoromethanesulfonate>\n",
      "cP4 aSO3 <Molecule: 776 methyltributylphosphonium triflate>\n",
      "cIm aNC[C] <Molecule: 781 3-hexyl-1-methylimidazolium tricyanomethanide>\n",
      "cIm aPO2 <Molecule: 784 1-ethyl-3-methylimidazolium dimethylphosphate>\n",
      "cIm aNC[S] <Molecule: 786 1-ethyl-3-methylimidazolium thiocyanate>\n",
      "cN4pi aNC[S] <Molecule: 795 1-butyl-1-methylpiperidinium thiocyanate>\n",
      "cIm aNC[S] <Molecule: 796 1-hexyl-3-methylimidazolium thiocyanate>\n",
      "cPyrr aNC[S] <Molecule: 806 1-ethyl-1-methylpyrrolidinium thiocyanate>\n",
      "cIm aNC[B] <Molecule: 833 1-ethyl-3-methylimidazolium tetracyanoborate>\n",
      "cIm aNC[B] <Molecule: 834 1-hexyl-3-methylimidazolium tetracyanoborate>\n",
      "cIm aCO2 <Molecule: 877 1-hexyl-3-methylimidazolium propanoate>\n",
      "cIm aSO3 <Molecule: 888 1-ethyl-3-methylimidazolium methanesulfonate>\n",
      "cP4 aSI <Molecule: 965 Tributylmethylphosphonium bis[(trifluoromethyl)sulfonyl]imide>\n",
      "cIm aSO4 <Molecule: 1089 1-ethyl-3-methylimidazolium methylsulfate>\n",
      "cIm aPO2 <Molecule: 1105 1-ethyl-3-methylimidazolium diethylphosphate>\n",
      "cP4 aPO2 <Molecule: 1196 tributylethylphosphonium diethylphosphate>\n",
      "cIm aSO4 <Molecule: 1226 1-butyl-3-methylimidazolium methyl sulfate>\n",
      "cP4 aSO4 <Molecule: 1227 tributylmethylphosphonium methyl sulfate>\n",
      "cIm aSO4 <Molecule: 1229 1-hexyl-3-methylimidazolium methyl sulfate>\n",
      "cPyrr aSO4 <Molecule: 1233 1-butyl-1-methylpyrrolidinium methyl sulfate>\n",
      "cPy aSO4 <Molecule: 1236 1-butylpyridinium methyl sulfate>\n",
      "cIm aSO4 <Molecule: 1239 1-ethyl-3-methylimidazolium ethyl sulfate>\n",
      "cPyrr aSO4 <Molecule: 1241 1-ethyl-1-methylpyrrolidinium ethyl sulfate>\n",
      "cPy aSO4 <Molecule: 1247 1-ethylpyridinium ethyl sulfate>\n",
      "cIm aSO4 <Molecule: 1248 1-butyl-3-methyl-1H-imidazolium ethyl sulfate>\n",
      "cIm aSO4 <Molecule: 1249 1-hexyl-3-methylimidazolium ethyl sulfate>\n",
      "cIm aPO2 <Molecule: 1256 1-hexyl-3-methylimidazolium dimethyl phosphate>\n"
     ]
    }
   ],
   "source": [
    "for mol in mols:\n",
    "    mol.selected = False\n",
    "    cation = mol.cation\n",
    "    anion = mol.anion\n",
    "    if cation.duplicate is not None:\n",
    "        cation = ions.get(cation.duplicate)\n",
    "    if anion.duplicate is not None:\n",
    "        anion = ions.get(anion.duplicate)\n",
    "    if cation.selected and anion.selected:\n",
    "        mol.selected = True\n",
    "        print(mol.cation.category, mol.anion.category, mol)\n",
    "session.commit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Fit density and viscosity for selected molecuels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "pycharm": {},
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "mols.update({'fit':None})\n",
    "session.commit()\n",
    "#for mol in mols.filter(Molecule.selected==True):\n",
    "#    print(mol)\n",
    "#    try:\n",
    "#        score = mol.fit_density()\n",
    "#        print(score)\n",
    "#    except:\n",
    "#        pass\n",
    "#    print(mol.fit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {}
   },
   "source": [
    "## Misc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "is_executing": false
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Molecule: 210 triethylammonium acetate>,\n",
       " <Molecule: 1289 triethylammonium hydrogen sulfate>,\n",
       " <Molecule: 1304 triethylammonium dihydrogen phosphate>]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ion = ions.get(185)\n",
    "ion.molecules.all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Ion +1: 2 1-butyl-3-methylimidazolium>\n",
      "<Ion -1: 3 bis(fluorosulfonyl)imide>\n"
     ]
    }
   ],
   "source": [
    "mol = mols.get(1)\n",
    "print(mol.cation)\n",
    "print(mol.anion)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<Data: Viscosity: 273.1 101.0 0.098800>, <Data: Viscosity: 278.1 101.0 0.076500>, <Data: Viscosity: 283.1 101.0 0.060400>, <Data: Viscosity: 288.1 101.0 0.048600>, <Data: Viscosity: 293.1 101.0 0.039700>, <Data: Viscosity: 298.1 101.0 0.032900>, <Data: Viscosity: 303.1 101.0 0.027600>, <Data: Viscosity: 313.1 101.0 0.020220>, <Data: Viscosity: 323.1 101.0 0.015350>, <Data: Viscosity: 333.1 101.0 0.012010>, <Data: Viscosity: 343.1 101.0 0.009650>, <Data: Viscosity: 353.1 101.0 0.007920>, <Data: Viscosity: 363.1 101.0 0.006630>]\n"
     ]
    }
   ],
   "source": [
    "mol = mols.get(1)\n",
    "vis = session.query(Property).filter(Property.name=='Viscosity').first()\n",
    "datas = mol.datas.filter(Data.property==vis)\n",
    "print(datas.all())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Ion -1: 75 4,5-dicyano-2-(trifluoromethyl)imidazolide>\n",
      "<Ion +1: 367 1-butyl-2,3,4,5-tetramethylimidazolium>\n",
      "<Ion +1: 368 1,2,3,4,5-pentamethylimidazolium>\n",
      "<Ion +1: 420 3-butyl-1,2,4,5-tetramethyl-1H-imidazol-3-ium>\n",
      "<Ion +1: 692 1-butyl-1H-benzimidazolium>\n",
      "<Ion -1: 761 L-histidinate>\n",
      "<Ion -1: 793 4,5-dicyanoimidazolide>\n"
     ]
    }
   ],
   "source": [
    "import pybel\n",
    "s = pybel.Smarts('n1cncc1[#6]')\n",
    "for ion in ions.filter(Ion.smiles!=None):\n",
    "    py_mol = pybel.readstring('smi', ion.smiles)\n",
    "    if s.findall(py_mol) != []:\n",
    "        print(ion)   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
